﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace TestcraftLibrary
{
    public class ServerChunkManager
    {
        private ServerConfiguration configuration;
        private ChunkIndex index;

        public ServerChunkManager(ServerConfiguration config)
        {
            this.configuration = config;
            this.index = new ChunkIndex(config.ChunkIndexPath);

        }

        public void LoadPlayerChunks(Player player)
        {
            Vector3 playerPosition = player.Position;
            int chunkX = (int)Math.Floor(playerPosition.X / Chunk.CHUNK_HORIZONTAL_SIZE);
            int chunkY = (int)Math.Floor(playerPosition.Z / Chunk.CHUNK_HORIZONTAL_SIZE);

            //List<Point> chunkLocations = this.GetPointsInCircle(chunkX, chunkY, this.configuration.ChunkRadius);

            
        }

        private List<Point> GetPointsInCircle(int originX, int originY, int radius)
        {
            List<Point> points = new List<Point>();
            for (int y = 0; y < radius; y++)
            {
                for (int x = 0; x < radius; x++)
                {
                    double length = Math.Sqrt(Math.Pow(x, 2.0) + Math.Pow(y, 2.0));
                    if (length <= radius)
                    {
                        points.Add(new Point(originX + x, originY + y));
                        points.Add(new Point(originX + -x, originY + y));
                        points.Add(new Point(originX + x, originY + -y));
                        points.Add(new Point(originX + -x, originY + -y));
                    }
                }
            }

            return points;
        }


    }
}
